package com.ruoyi.legal.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.ResponseModel;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.Pages;
import com.ruoyi.common.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.legal.domain.PackXjcl;
import com.ruoyi.legal.service.IPackXjclService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * 虚假材料备份Controller
 * 
 * @author xwj
 * @date 2025-06-05
 */
@RestController
@RequestMapping("/legal/packXjcl")
@Api(tags = "虚假材料备份")
public class PackXjclController extends BaseController {
    @Autowired
    private IPackXjclService packXjclService;

    /**
     * 查询虚假材料备份列表
     */
    @PostMapping("/list")
    @ApiOperation("分页查询")
    public TableDataInfo list(@RequestBody PackXjcl packXjcl) {
        startPage();
        List<PackXjcl> list = packXjclService.selectPackXjclList(packXjcl);
        return getDataTable(list);
    }

    @PostMapping("/listAll")
    @ApiOperation("不分页查询")
    public AjaxResult listAll(@RequestBody PackXjcl packXjcl) {
        startOrderBy();
        List<PackXjcl> list = packXjclService.selectPackXjclList(packXjcl);
        return success(list);
    }

    /**
     * 导出虚假材料备份列表
     */
    @Log(title = "虚假材料备份", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出")
    public void export(HttpServletResponse response, PackXjcl packXjcl) {
        List<PackXjcl> list = packXjclService.selectPackXjclList(packXjcl);
        ExcelUtil<PackXjcl> util = new ExcelUtil<PackXjcl>(PackXjcl.class);
        util.exportExcel(response, list, "虚假材料备份数据");
    }

    /**
     * 获取虚假材料备份详细信息
     */
    @GetMapping(value = "/info/{id}")
    @ApiOperation("详情")
    public AjaxResult info(@PathVariable("id") Long id)  {
        return success(packXjclService.selectPackXjclById(id));
    }

    /**
     * 新增虚假材料备份
     */
    @Log(title = "虚假材料备份", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    @ApiOperation("新增")
    public AjaxResult save(@RequestBody PackXjcl packXjcl) {
        SysUser user = getLoginUser().getUser();
        if(packXjcl.getId() == null) {
        packXjcl.setCreateId(user.getUserId());
            packXjcl.setCreateTime(DateUtils.getNowDate());
            packXjcl.setCreateBy(user.getNickName());
            packXjclService.insertPackXjcl(packXjcl);
        } else {
            packXjcl.setUpdateId(user.getUserId());
            packXjcl.setUpdateTime(DateUtils.getNowDate());
            packXjcl.setUpdateBy(user.getNickName());
            packXjclService.updatePackXjcl(packXjcl);
        }

        return success(packXjcl);
    }

    /**
     * 修改虚假材料备份
     */
    @Log(title = "虚假材料备份", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改")
    public AjaxResult update(@RequestBody PackXjcl packXjcl) {
        SysUser user = getLoginUser().getUser();
                packXjcl.setUpdateId(user.getUserId());
                packXjcl.setUpdateTime(DateUtils.getNowDate());
                packXjcl.setUpdateBy(user.getNickName());
        return success(packXjclService.updatePackXjcl(packXjcl));
    }

    /**
     * 删除虚假材料备份
     */
    @Log(title = "虚假材料备份", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除或批量删除")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(packXjclService.deletePackXjclByIds(ids));
    }

    @Log(title = "虚假材料备份", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    @ApiOperation("条件删除")
    public ResponseModel delete(@RequestBody PackXjcl packXjcl) {
        int num = packXjclService.delete(packXjcl);
        return ResponseModel.of(num);
    }

    @PostMapping("/queryPage")
    @ApiOperation("分页查询-mp")
    public ResponseModel<Pages<PackXjcl>> queryPage(@RequestBody PackXjcl packXjcl) {
        Pages<PackXjcl> page = packXjclService.queryPage(packXjcl);
        return ResponseModel.of(page);
    }
}
